import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonIOException;
import com.google.gson.JsonSyntaxException;

import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class Test {
    public static void main(String[] args) {
        Product product1 = new Product("product1", 1, 10);
        System.out.println(product1.toString());

        Gson gson = new GsonBuilder().setPrettyPrinting().create();
        try(FileWriter writer = new FileWriter("profitDit.json")) {
            String json1 = gson.toJson(product1);
            writer.write(json1);
        } catch (IOException e) {
            e.printStackTrace();
        }

        try {
            FileReader reader = new FileReader("profitDit2.json");
            Product product2 = gson.fromJson(reader, Product.class);
            System.out.println(product2.toString());
            reader.close();
        } catch (JsonSyntaxException | JsonIOException | IOException e) {
            e.printStackTrace();
        }


        String[] array1 = {"test", "write", "io", "thread"};
        try (BufferedWriter writer = new BufferedWriter(new FileWriter("profitDit.csv"))) {
            for (int i = 0; i < array1.length; i++) {
                writer.write(array1[i]);
                if (i < array1.length - 1) {
                    writer.write(",");
                }
            }
            writer.newLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
